<template>
    <el-dialog
      top="15px"
      :title="title"
      :visible.sync="show"
      width="720px"
      :before-close="clickClose"
    >
      <el-form label-position="left" label-width="130px">
        <el-form-item label="采购方">
          <el-input
            disabled
            :value="subForm.institutionName || ''"
            size="medium"
            class="contentItem"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="资产类型">
          <el-input
            disabled
            :value="subForm.assetTypeName || ''"
            size="medium"
            class="contentItem"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="项目类型">
          <el-input
            disabled
            :value="subForm.projectTypeName || ''"
            size="medium"
            class="contentItem"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="采购数量(tCO2e)">
          <el-input
            disabled
            :value="subForm.tradeQuantity || ''"
            size="medium"
            class="contentItem"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="询价(¥)">
          <el-input
            disabled
            :value="subForm.assetUnitPrice || ''"
            size="medium"
            class="contentItem"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="期望交割日期">
          <el-input
            disabled
            :value="subForm.deliveryTime || ''"
            size="medium"
            class="contentItem"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="期望交割方式">
          <el-input
            disabled
            :value="subForm.deliveryMethodName || ''"
            size="medium"
            class="contentItem"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="期望交割场所">
          <el-input
            disabled
            :value="subForm.deliveryExchangeName || ''"
            size="medium"
            class="contentItem"
          >
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="clickClose" class="light-green-btn">{{
          btnText
        }}</el-button>
      </div>
    </el-dialog>
  </template>
  <script>
  import { getDiliveryMethodeDict, getExchangeDict } from "@/config/dictHelper";
  import { getAccoutEnterPriseInfo } from "@/api/tenant";
  export default {
    name: "buyDetail",
    props: {
      form: {},
      title: "",
      dialogFormVisible: false,
    },
    data() {
      return {
        seletedDeliverMethod: "",
        deliverMethodList: [],
        seletedExchange: "",
        exchangeList: [],
        pickerOptions: {
          shortcuts: [
            {
              text: "今天",
              onClick(picker) {
                picker.$emit("pick", new Date());
              },
            },
            {
              text: "昨天",
              onClick(picker) {
                const date = new Date();
                date.setTime(date.getTime() - 3600 * 1000 * 24);
                picker.$emit("pick", date);
              },
            },
            {
              text: "一周前",
              onClick(picker) {
                const date = new Date();
                date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                picker.$emit("pick", date);
              },
            },
          ],
        },
        selectDate: "",
        btnText: "确定",
        subForm: {
          institutionName: '',
          assetTypeName: '',
          projectTypeName: '',
          tradeQuantity: '',
          assetUnitPrice: '',
          deliveryTime: '',
          deliveryMethodName: '',
          deliveryExchangeName: ''
        },
        subTitle: "",
        show: false,
      };
    },
    watch: {
      title() {
        this.subTitle = this.title;
      },
      form() {
        if (this.form && typeof this.form === 'object') {
          this.subForm = { ...this.form };
        } else {
          this.subForm = {
            institutionName: '',
            assetTypeName: '',
            projectTypeName: '',
            tradeQuantity: '',
            assetUnitPrice: '',
            deliveryTime: '',
            deliveryMethodName: '',
            deliveryExchangeName: ''
          };
        }
        // this.initParams();
      },
      dialogFormVisible() {
        this.show = this.dialogFormVisible;
      },
    },
    methods: {
      clickClose() {
        this.$emit("changeDialogFormVisible", false);
        this.show = false;
      },
      checkParam(value) {
        return !value || value === "" || value === "--" || value === "/";
      },
      initParams() {
        // this.subForm.assetTypeName = this.checkParam(this.subForm.assetType) ? '全部':this.subForm.assetType
        // this.subForm.projectTypeName = this.checkParam(this.subForm.projectType) ? '全部':this.subForm.projectType
        // this.subForm.tradeQuantity = this.checkParam(this.subForm.tradeQuantity) ? '--':this.subForm.tradeQuantity
        this.subForm.assetUnitPrice = this.checkParam(this.subForm.assetUnitPrice)
          ? "0"
          : this.subForm.assetUnitPrice;
        // this.subForm.deliveryTime = this.subForm.deliveryTime !== null && this.subForm.deliveryTime !== '' ? this.subForm.deliveryTime.split(' ')[0]:''
        // this.subForm.deliveryTime = this.checkParam(this.subForm.deliveryTime) ? '--':this.subForm.deliveryTime
        // this.subForm.deliveryMethodName = this.checkParam(this.subForm.deliveryMethod) ? '全部':this.subForm.deliveryMethod
        // this.subForm.deliveryExchangeName = this.checkParam(this.subForm.deliveryExchange) ? '全部':this.subForm.deliveryExchange
        // for(var i in this.subForm){
        //   if(this.checkParam(this.subForm[i])){
  
        //   }
        // }
         if(this.form && this.form.publisherId) {
          getAccoutEnterPriseInfo(this.form.publisherId).then((res) => {
            this.subForm.institutionName = res.tenantName;
          });
        }
        
      },
    },
    created() {},
    mounted() {
      this.subTitle = this.title;
      if (this.form && typeof this.form === 'object') {
        this.subForm = this.form;
      } else {
        this.subForm = {
          institutionName: '',
          assetTypeName: '',
          projectTypeName: '',
          tradeQuantity: '',
          assetUnitPrice: '',
          deliveryTime: '',
          deliveryMethodName: '',
          deliveryExchangeName: ''
        };
      }
      this.initParams();
      this.show = this.dialogFormVisible;
      let data = getDiliveryMethodeDict(this.$store);
      this.deliverMethodList = [];
      data.map((v) => {
        let item = {
          value: "",
          label: "",
        };
        item.value = v.value;
        item.label = v.name;
        this.deliverMethodList.push(item);
      });
      data = getExchangeDict(this.$store);
      this.exchangeList = [];
      data.map((v) => {
        let item = {
          value: "",
          label: "",
        };
        item.value = v.value;
        item.label = v.name;
        this.exchangeList.push(item);
      });
    },
  };
  </script>
  <style scoped>
  .contentItem {
    width: 100%;
    top: -5px;
  }
  </style>